package org.nokatag.dbgrid;



import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.FilterConfig;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.noka.gson.Gson;
import org.noka.gson.reflect.TypeToken;
import org.nokatag.password.AESPlus;
import org.nokatag.system.BugInfoWrint;
import org.nokatag.system.Concest;
import org.nokatag.system.DBCon;
import org.nokatag.system.NLoadFun;
import org.nokatag.system.SQLCheck;

/**
 * dbgrid 数据服务
 * @author rebin
 *
 */
public class NDBGridDataServer {

	/**
	 * 自定义类
	 * @param request
	 * @param response
	 * @param config
	 */
	public void dataRclass(HttpServletRequest request,HttpServletResponse response,FilterConfig config){
		String path = request.getParameter("dataclass");
		String sql=request.getParameter("sql");
		String ng =request.getParameter("ng");
		String nkdbgridkey =  request.getParameter("nkdbgridkey");
		String cells = request.getParameter("nkdbgridcells");
		String foldingline = request.getParameter("foldingline");
		response.setContentType("text/json");
		if(null!=nkdbgridkey && null!=cells){//保存设置
			NDBGridCellsGet gridSetCells = new NDBGridCellsGet();
			gridSetCells.getCells(request, response, config);
		}else if(null!=nkdbgridkey && null==cells && null==foldingline){//清除设置
			NDBGridCellsGet gridSetCells = new NDBGridCellsGet();
			gridSetCells.clearSet(request, response, config);
		}else if(null!=nkdbgridkey && null!=foldingline){//折行设置
			NDBGridCellsGet gridSetCells = new NDBGridCellsGet();
			if("true".equalsIgnoreCase(foldingline)){
				gridSetCells.getFoldingLine(request, response, config);
			}else{
				gridSetCells.clearFoldingLine(request, response, config);//不为true清除折行
			}
		}
		else{
			try {
				if(sql!=null && sql.trim().length()>1)
					sql=AESPlus.decrypt(sql,Concest.SQLKEY);//sql语句
				if(path!=null && path.trim().length()>1){//自定义类
					String spage=request.getParameter("spage");
					String pagedescorname=request.getParameter("pagedescorname");
					String pagedescorasc=request.getParameter("pagedescorasc");
					path=AESPlus.decrypt(path,Concest.SQLKEY);//自定义类
					NLoadFun nloadFun = new NLoadFun();
					DataInterface dain = (DataInterface)nloadFun.getBean(path);
					String body=dain.dataRunte(request, response,sql,spage,pagedescorname,pagedescorasc);
					OutputStream out = response.getOutputStream();
					Writer wr=new OutputStreamWriter(out,Concest.ENCODING);
					wr.write(body.toString());
					wr.flush();
					out.flush();
					wr.close();
					out.close();
				}else if(null!=ng && "1".equals(ng)){//获取列名
					getCellName(request,response);
				}else{//sql方式加载数据
					getData(request,response,config);
				}
			} catch (Exception e) {
				BugInfoWrint.Print("noka data is : " + "file:"+ Concest.ROOTDIR + "/WEB-INF/classes" + " " + path);
				BugInfoWrint.Print(e);
			}
		}
	}
	
	protected  void getData(HttpServletRequest request,HttpServletResponse response,FilterConfig config){
		StringBuffer body=new StringBuffer();
		NDBGridDataItem da =sqlData(request);
		body.append("{");
		body.append("options:{");
		body.append("pagecont:'"+da.getPages()+"',");
		body.append("showpage:'"+da.getNowpage()+"',");
		body.append("startrow:'"+da.getStartrow()+"',");
		body.append("endrow:'"+da.getEndrow()+"',");
		body.append("pagesize:'"+da.getPagesize()+"',");
		if(null!=da.getSumCells() && !da.getSumCells().isEmpty()){
			Gson gson = new Gson();
			body.append("sumcells:"+gson.toJson(da.getSumCells())+",");
		}
		body.append("lastRow:'"+da.getLastRow()+"'");
		body.append("},");
		//-----------外部方法返回值---------------------------------
		String onDataLoad = request.getParameter("onDataLoad");
		if(null!=onDataLoad && onDataLoad.trim().length()>1){
			try{
				onDataLoad=AESPlus.decrypt(onDataLoad,Concest.SQLKEY);//自定义类
				NLoadFun nloadFun = new NLoadFun();
				OnDBGridDataLoadInterface dain = (OnDBGridDataLoadInterface)nloadFun.getBean(onDataLoad);
				
				String sql=request.getParameter("sql");
				sql=AESPlus.decrypt(sql,Concest.SQLKEY);//sql语句
				String queryJSON = request.getParameter("queryjson");//查询的json字符串
				Gson gson = new Gson();
				List<Map<String,String>> person = gson.fromJson(queryJSON,new TypeToken<List<Map<String,String>>>(){}.getType());//map key name and value
				String run = dain.OnDataLoad(sql,person);
				if(run!=null && run.trim().length()>0){
					body.append("userData:"+run+",");
				}
			}catch(Exception se){}
		}
		//---------------------------------------------------------
		body.append("rows:[");
		String sc="";
		for(Map<String,String> row :da.getRows()){
			String rs="";
			for (Map.Entry<String, String> entry : row.entrySet()) {
				   if(null == entry.getValue() || entry.getValue().trim().length()<1){
					   entry.setValue("&nbsp;");
				   }
				   rs+=",\""+entry.getKey()+"\":\""+entry.getValue().replace("\\","\\\\").replace("\'","\\'").replace("\"","\\\"")+"\"";
			}
			rs=rs.substring(1,rs.length());
			sc+=",{"+rs+"}";
			sc=sc.replace("\r","\\r").replace("\n","\\n").replace("\t","\\t");
		}
		if(sc.length()>2)
			sc=sc.substring(1,sc.length());
		body.append(sc);
		body.append("]}");
		try{
			OutputStream out = response.getOutputStream();
			Writer wr=new OutputStreamWriter(out,Concest.ENCODING);
			BugInfoWrint.Print(body.toString());
			wr.write(body.toString());
			wr.flush();
			out.flush();
			wr.close();
			out.close();
		}catch(Exception e){
			BugInfoWrint.Print(e);
		}
	}
	/**
	 * 解析查询条件
	 * @param request
	 * @return
	 */
	protected  NDBGridDataItem sqlData(HttpServletRequest request){
		String srcsql=request.getParameter("sqlwhere");
		String sql=request.getParameter("sql");
		String sumsql = request.getParameter("sumsql");
		String countsql=request.getParameter("countsql");
		String cell = request.getParameter("cells");
		if(null==sql)
			return null;
		sql=AESPlus.decrypt(sql,Concest.SQLKEY);//sql语句
		sumsql=(null==sumsql?sql:AESPlus.decrypt(sumsql,Concest.SQLKEY));//树形状态下汇总sql语句
		countsql=(null==countsql?sql:AESPlus.decrypt(countsql,Concest.SQLKEY));//总行数sql语句
		List<CellParItem> parList=new ArrayList<CellParItem>();
		Map<String,String>  svaluelist = new HashMap<String,String>();
		List<CellParItem> cellName = null;
		//------------------------------------------------------------------------------------
		if(null!=cell){
			Gson gson = new Gson();
			cellName = gson.fromJson(cell, new TypeToken<List<CellParItem>>(){}.getType());
		}
		try{
			if((null==cellName || cellName.isEmpty()) && null!=sql){
				cellName = NDBGridUtil.getCellType(request,sql);
			}
		}catch(Exception e){}//取出列名及类型 1 子表    2 序号  3 单选  4 多选    5 数据列    width:200,show:1|
		String selectwheresql = null;
		if(srcsql!=null){
			selectwheresql=new String("");
			String sqlwhere=AESPlus.decrypt(srcsql,Concest.SQLKEY);//sql查询条件（原始数据）${org.word.jsp.name} like '%$[wdname,${org.word.jsp.name}]%'  | #[ano,and^并且!or^或者]# ${org.word.jsp.notes} like
			sqlwhere=" and "+sqlwhere;
			String[] selectfiledssn = sqlwhere.split("\\|");
			int ai=1;
			for(int i=0;i<selectfiledssn.length;i++){ //循环查询条件
			   String tempend = selectfiledssn[i].replace("$n", " ");
			   try{
		    		// #[name,1^第一级!2^第二级]#  $[name,中文名,list,1^第一级!2^第二级]   type:String,Long,Integer,Date,float,double
		    		//---------------------查询值-------------------------------------------------------------
		    		tempend=tempend.replace("'%$[", "%$[").replace("]%'","]%");//去掉两端的单引号
		    		tempend=tempend.replace("'$[", "$[").replace("]'","]");//去掉两端的单引号
		    		String subtemp = tempend.substring(tempend.indexOf("$[")+2,tempend.lastIndexOf("]"));
		    		String[] slw = tempend.substring(tempend.indexOf("$[")+2,tempend.lastIndexOf("]")).split(",");//查询数组
		    		String selectname2 = slw[0];//查询框名字
		    		String htmlParmeter = request.getParameter(selectname2);//取得查询值
		    		if(SQLCheck.sql_inj(htmlParmeter)){
		    			Integer ts=0;//默认没有模糊查询
		    			String tem_selectwheresql="";
		    			tem_selectwheresql=tempend.replace("$["+subtemp+"]", "?");//只有名字，中文名
	    				ts=NDBGridUtil.MQuery(tempend,"$["+subtemp+"]");
	    				String[] vs = htmlParmeter.replaceAll("\\s{1,}", " ").split(",");//以逗号分隔
			    		String[] va = htmlParmeter.replaceAll("\\s{1,}", " ").split(" ");//以空格分隔
			    		
			    		String lop = null;
	    				String tlop = null;
	    				String gf = null;//值前后缀
	    				
		    			switch(ts){
		    			case 0:
		    				parList.add(new CellParItem(NDBGridUtil.getType(cellName,tem_selectwheresql),htmlParmeter,ai++));
		    				selectwheresql+=tem_selectwheresql;
		    				break;
		    			case 1:
		    				parList.add(new CellParItem(NDBGridUtil.getType(cellName,tem_selectwheresql),"%"+htmlParmeter+"%",ai++));
		    				selectwheresql+=tem_selectwheresql.replace("%?%","?");
		    				break;
		    			case 2:
		    				parList.add(new CellParItem(NDBGridUtil.getType(cellName,tem_selectwheresql),"%"+htmlParmeter,ai++));
		    				selectwheresql+=tem_selectwheresql.replace("%?","?");
		    				break;
		    			case 3:
		    				parList.add(new CellParItem(NDBGridUtil.getType(cellName,tem_selectwheresql),htmlParmeter+"%",ai++));
		    				selectwheresql+=tem_selectwheresql.replace("?%","?");
		    				break;
		    			case 4://in 多个值用in查询
		    				String vp = "";
		    				if(vs.length<va.length){
		    					for(String v:va){
		    						vp+="?,";
			    					parList.add(new CellParItem(NDBGridUtil.getType(cellName,tem_selectwheresql),v,ai++));
			    				}
		    				}else{
		    					for(String v:vs){
		    						vp+="?,";
			    					parList.add(new CellParItem(NDBGridUtil.getType(cellName,tem_selectwheresql),v,ai++));
			    				}
		    				}
		    				
		    				if(vp.endsWith("?,"))
		    					vp=vp.substring(0,vp.length()-1);
		    				selectwheresql+=tem_selectwheresql.replace("?",vp);
		    				break;
		    			case 5://like 多个值用like查询
		    				lop = "(";
		    				tlop = tem_selectwheresql;
		    				tlop = tlop.replace("and", "");
		    				if(tlop.indexOf("&")!=-1){
		    					gf = tlop.substring(tlop.indexOf("&")+1,tlop.indexOf("&")+2);
		    					tlop = tlop.replace("&"+gf,"");
		    				}
		    				if(tlop.indexOf("#[")!=-1 && tlop.indexOf("]#")!=-1){
		    					tlop = tlop.substring(tlop.indexOf("]#")+2,tlop.length());
		    				}
		    				if(vs.length<va.length){
		    					for(String v:va){
		    						lop+=tlop.replace("%?%","?") + " or ";
		    						if(null!=gf){
		    							v=gf+v+gf;
		    						}
			    					parList.add(new CellParItem(NDBGridUtil.getType(cellName,tem_selectwheresql),"%"+v+"%",ai++));
			    				}
		    				}else{
		    					for(String v:vs){
			    					lop+=tlop.replace("%?%","?") + " or ";
			    					if(null!=gf){
		    							v=gf+v+gf;
		    						}
				    				parList.add(new CellParItem(NDBGridUtil.getType(cellName,tem_selectwheresql),"%"+v+"%",ai++));
			    				}
		    				}
		    				if(lop.endsWith(" or "))
		    					lop = " and "+lop.substring(0,lop.length()-3)+")";
		    				selectwheresql+=tem_selectwheresql.substring(0,tem_selectwheresql.indexOf("]#")+2)+" "+lop;
		    				break;
		    			case 6://like 多个值用like查询
		    				lop = "(";
		    				tlop = tem_selectwheresql;
		    				tlop = tlop.replaceAll("(?i)and", "");
		    				if(tlop.indexOf("&")!=-1){
		    					gf = tlop.substring(tlop.indexOf("&")+1,tlop.indexOf("&")+2);
		    					tlop = tlop.replace("&"+gf,"");
		    				}
		    				if(tlop.indexOf("#[")!=-1 && tlop.indexOf("]#")!=-1){
		    					tlop = tlop.substring(tlop.indexOf("]#")+2,tlop.length());
		    				}
		    				if(vs.length<va.length){
		    					for(String v:va){
		    						lop+=tlop.replace("%?","?") + " or ";
		    						if(null!=gf){
		    							v=gf+v+gf;
		    						}
			    					parList.add(new CellParItem(NDBGridUtil.getType(cellName,tem_selectwheresql),"%"+v,ai++));
			    				}
		    				}else{
		    					for(String v:vs){
			    					lop+=tlop.replace("%?","?") + " or ";
			    					if(null!=gf){
		    							v=gf+v+gf;
		    						}
				    				parList.add(new CellParItem(NDBGridUtil.getType(cellName,tem_selectwheresql),"%"+v,ai++));
			    				}
		    				}
		    				if(lop.endsWith(" or "))
		    					lop =" and "+ lop.substring(0,lop.length()-3)+")";
		    				selectwheresql+=tem_selectwheresql.substring(0,tem_selectwheresql.indexOf("]#")+2)+" "+lop;
		    				break;
		    			case 7://like 多个值用like查询
		    				lop = "(";
		    				tlop = tem_selectwheresql;
		    				tlop = tlop.replace("and", "");
		    				if(tlop.indexOf("&")!=-1){
		    					gf = tlop.substring(tlop.indexOf("&")+1,tlop.indexOf("&")+2);
		    					tlop = tlop.replace("&"+gf,"");
		    				}
		    				if(tlop.indexOf("#[")!=-1 && tlop.indexOf("]#")!=-1){
		    					tlop = tlop.substring(tlop.indexOf("]#")+2,tlop.length());
		    				}
		    				if(vs.length<va.length){
		    					for(String v:va){
		    						lop+=tlop.replace("?%","?") + " or ";
		    						if(null!=gf){
		    							v=gf+v+gf;
		    						}
			    					parList.add(new CellParItem(NDBGridUtil.getType(cellName,tem_selectwheresql),v+"%",ai++));
			    				}
		    				}else{
		    					for(String v:vs){
			    					lop+=tlop.replace("?%","?") + " or ";
			    					if(null!=gf){
		    							v=gf+v+gf;
		    						}
				    				parList.add(new CellParItem(NDBGridUtil.getType(cellName,tem_selectwheresql),v+"%",ai++));
			    				}
		    				}
		    				if(lop.endsWith(" or "))
		    					lop = " and "+lop.substring(0,lop.length()-3)+")";
		    				selectwheresql+=tem_selectwheresql.substring(0,tem_selectwheresql.indexOf("]#")+2)+" "+lop;
		    				break;
		    			case 8://多列单值,查询  a;b  like '$[sss,cc]'
			    			{
			    				tlop = tem_selectwheresql.replace("%?%", "?");// and {a,b} like ?
			    				String[] st = tlop.split("}");// st   [0]= and {a,b  [1]=} like ?
			    				String[] st2 = st[0].split("\\{");// and {a,b  =>  [0]= and    [1]= a,b
			    				lop=st2[0] + "( 1<>1 "; // and (
			    				String[] cn = st2[1].split(",");//a,b => [a,b]
			    				for(int c=0;c<cn.length;c++){//a,b
			    					lop+=" or " + cn[c]+" "+st[1]+"  ";
			    					parList.add(new CellParItem(NDBGridUtil.getType(cellName,tem_selectwheresql),"%"+htmlParmeter+"%",ai++));
			    				}
			    				lop+=")";
			    				selectwheresql+=lop;
			    			}	
		    				break;
		    			case 9://多列单值,查询  a;b  like '$[sss,cc]'
		    			{
		    				tlop = tem_selectwheresql.replace("%?", "?");// and {a,b} like ?
		    				String[] st = tlop.split("}");// st   [0]= and {a,b  [1]=} like ?
		    				String[] st2 = st[0].split("\\{");// and {a,b  =>  [0]= and    [1]= a,b
		    				lop=st2[0] + "( 1<>1 "; // and (
		    				String[] cn = st2[1].split(",");//a,b => [a,b]
		    				for(int c=0;c<cn.length;c++){//a,b
		    					lop+=" or " + cn[c]+" "+st[1]+"  ";
		    					parList.add(new CellParItem(NDBGridUtil.getType(cellName,tem_selectwheresql),"%"+htmlParmeter,ai++));
		    				}
		    				lop+=")";
		    				selectwheresql+=lop;
		    			}	
	    				break;
		    			case 10://多列单值,查询  a;b  like '$[sss,cc]'
		    			{
		    				tlop = tem_selectwheresql.replace("?%", "?");// and {a,b} like ?
		    				String[] st = tlop.split("}");// st   [0]= and {a,b  [1]=} like ?
		    				String[] st2 = st[0].split("\\{");// and {a,b  =>  [0]= and    [1]= a,b
		    				lop=st2[0] + "( 1<>1 "; // and (
		    				String[] cn = st2[1].split(",");//a,b => [a,b]
		    				for(int c=0;c<cn.length;c++){//a,b
		    					lop+=" or " + cn[c]+" "+st[1]+"  ";
		    					parList.add(new CellParItem(NDBGridUtil.getType(cellName,tem_selectwheresql),htmlParmeter+"%",ai++));
		    				}
		    				lop+=")";
		    				selectwheresql+=lop;
		    			}	
	    				break;
		    			case 11://多列单值,查询  a;b  like '$[sss,cc]'
		    			{
		    				tlop = tem_selectwheresql.replace("?", "?");// and {a,b} like ?
		    				String[] st = tlop.split("}");// st   [0]= and {a,b  [1]=} like ?
		    				String[] st2 = st[0].split("\\{");// and {a,b  =>  [0]= and    [1]= a,b
		    				lop=st2[0] + "( 1<>1 "; // and (
		    				String[] cn = st2[1].split(",");//a,b => [a,b]
		    				for(int c=0;c<cn.length;c++){//a,b
		    					lop+=" or " + cn[c]+" "+st[1]+"  ";
		    					parList.add(new CellParItem(NDBGridUtil.getType(cellName,tem_selectwheresql),htmlParmeter,ai++));
		    				}
		    				lop+=")";
		    				selectwheresql+=lop;
		    			}	
	    				break;
		    			}
		    			svaluelist.put(selectname2, htmlParmeter);
		    			String htmlParmeter_show = request.getParameter(selectname2+"_show");//取得查询值
		    			if(htmlParmeter_show!=null && htmlParmeter_show.trim().length()>0)
		    				svaluelist.put(selectname2+"_show", htmlParmeter_show);
		    		}
		    		//-----------------处理查询条件连接-----------------------------------------------------------
		    		if(tempend.indexOf("#[")!=-1 && tempend.indexOf("]#")!=-1){
			    		//------------------------查询条件--------------------------------------------------------
			    		String[] selectwhere = tempend.substring(tempend.indexOf("#[")+2,tempend.indexOf("]#")).split(",");//条件值
			    		String sname = "";//查询条件名字
			    		String svalue="";//查询值
			    		if(selectwhere!=null && selectwhere.length>0){
			    			sname = selectwhere[0];
			    			svalue = selectwhere[1];
			    		}
			    		String selectwhere2 = request.getParameter(sname);
			    		//----------------------查询条件-----------------------------------------------
			    		if(selectwhere2!=null && sname.trim().length()>0 && svalue.trim().length()>0 && selectwheresql!=null && selectwheresql.trim().length()>0){
			    			if(selectwhere2.equalsIgnoreCase("or") || selectwhere2.equalsIgnoreCase("and")){
			    				selectwheresql = selectwheresql.replace("#["+sname+","+svalue+"]#", selectwhere2);
			    				svaluelist.put(sname, selectwhere2);
			    			}
			    			BugInfoWrint.Print("查询条件："+selectwhere2);
			    		}
		    		}
			   }catch(Exception se){
		    		se.printStackTrace();
		    	}
			}
		}
		
	//-------------------------------------------------------------------------------
	try{
		Connection con=DBCon.getCon();//sql语句
		DatabaseMetaData dmd = con.getMetaData();
		String dbname = dmd.getDatabaseProductName();
		NDBGridData da = null;
		BugInfoWrint.Print("----------------------database name:"+dbname+"--------------------------------");
		if(Concest.DBGRID_DATA_SERVER_CLASS!=null){
			NLoadFun nloadFun = new NLoadFun();
			da= (NDBGridData)nloadFun.getBean(Concest.DBGRID_DATA_SERVER_CLASS);
		}else if(dbname.equalsIgnoreCase("Oracle"))	
			da = new NDBGridOracle();
		else if(dbname.equalsIgnoreCase("Microsoft SQL Server"))
			da = new NDBGridDataSQLServer();
		else if(dbname.equalsIgnoreCase("MySQL"))
			da = new NDBGridDataMySQL();
		else if(dbname.equalsIgnoreCase("PostgreSQL"))
			da = new NDBGridPostgre();
		else if(dbname.startsWith("DB2"))
			da = new NDBGridDB2();
		else if(dbname.equalsIgnoreCase("Greenplum"))
			da = new NDBGridPostgre();
		else
			da = new NDBGridData();	
		Long showPage = 0L;
		Long pageSize = 1L;
		try{
			showPage = Long.parseLong(request.getParameter("spage"));
			pageSize = (request.getParameter("pagesize")==null || "".equals(request.getParameter("pagesize")))?null:Long.parseLong(request.getParameter("pagesize"));
		}catch(Exception se){}
		String pagedescorname=request.getParameter("pagedescorname");
		String pagedescorasc=request.getParameter("pagedescorasc");
		String formatcell=request.getParameter("formatcell");
		String sumcells = request.getParameter("sumcellidexs");
		String sumformatcell=request.getParameter("sumformatcell");
		NDBGridDataItem ndbDataItem = da.DataQuery(new NDBGridDataQueryItem(showPage, pageSize, sql,selectwheresql, parList, pagedescorname, pagedescorasc,formatcell,cellName,sumcells,sumformatcell,request,sumsql,countsql), con);
		try{
			if(null==ndbDataItem.getCellName() || ndbDataItem.getCellName().isEmpty()){
				if(null!=cellName && !cellName.isEmpty()){
					List<String> cName = new ArrayList<String>();
					for(CellParItem cp:cellName){
						cName.add(cp.getCellname());
					}
					ndbDataItem.setCellName(cName);
				}
			}
		}catch(Exception e){}
		return ndbDataItem;
	}catch(Exception se){
		 se.printStackTrace();
	}
		return null;
	}
	//===================获取列名====================================
	protected void getCellName(HttpServletRequest request,HttpServletResponse response){
		String sql = request.getParameter("sql");
		String cells=request.getParameter("cells");//width:100,show:1|width:100,show:1
		String bodyStr = "";
		if(null!=sql){
			sql=AESPlus.decrypt(sql,Concest.SQLKEY);//sql语句
			if(sql.indexOf("$[")!=-1){
				sql=sql.replace("$[where]", "");
			}
			StringBuffer body = new StringBuffer();
			List<CellParItem> Cellname = NDBGridUtil.getCellType(request,sql);//取出列名及类型 1 子表    2 序号  3 单选  4 多选    5 数据列    width:200,show:1|
			if(cells!=null && cells.trim().length()>0){
				String[] arg=cells.split("\\|");
				for(int i=0;i<Cellname.size();i++){
					if(i<arg.length)
						body.append("{title : '"+Cellname.get(i).getCellname()+"',"+arg[i]+",aircell:[]},");
					else
						body.append("{title : '"+Cellname.get(i).getCellname()+"',width : 100,show:4,aircell:[]},");
				}
			}else{
				for(int i=0;i<Cellname.size();i++){
					body.append("{title : '"+Cellname.get(i).getCellname()+"',width : 100,show:1,aircell:[]},");
				}
			}
			if(body.length()>2)
				bodyStr= "["+body.substring(0,body.length()-1)+"]";
			try{
				OutputStream out = response.getOutputStream();
				Writer wr=new OutputStreamWriter(out,Concest.ENCODING);
				BugInfoWrint.Print(body.toString());
				wr.write(bodyStr);
				wr.flush();
				out.flush();
				wr.close();
				out.close();
			}catch(Exception e){
				BugInfoWrint.Print(e);
			}
		}
	}
}
